from tortoise import fields
from tortoise.models import Model


class AccountORM(Model):
    id = fields.IntField(primary_key=True, unique=True, generated=True)
    username = fields.CharField(max_length=32, null=False, unique=True)
    email = fields.CharField(max_length=64, null=False, default="")
    hashed_password = fields.CharField(max_length=255, null=False)
    role = fields.CharField(max_length=32, null=False, default="visitor")
    saved_matrices = fields.CharField(max_length=255, default="[]")
    created_at = fields.DatetimeField(null=False, auto_now_add=True)
    updated_at = fields.DatetimeField(auto_now=True)
    error = fields.CharField(max_length=32, default="")

    class Meta:
        table_description = "Account table"
        table = "account"

    def to_dict_public(self) -> dict:
        return {
            "id": self.id,
            "username": self.username,
        }

    def to_dict_complete(self) -> dict:
        return {
            "id": self.id,
            "username": self.username,
            "email": self.email,
            "role": self.role,
            "saved_matrices": self.saved_matrices,
            "error": self.error
        }


class QAs(Model):
    id = fields.IntField(primary_key=True, unique=True, generated=True)
    question = fields.CharField(max_length=1024, null=False)
    answer = fields.CharField(max_length=64, null=False)
    created_at = fields.DatetimeField(null=False, auto_now_add=True)
    updated_at = fields.DatetimeField(auto_now=True)

    class Meta:
        table_description = "QAs table"
        table = "QAs"


# Account_Pydantic = pydantic_model_creator(Account, name="Account")
# QAs_Pydantic = pydantic_model_creator(QAs, name="QAs")
